package com.wiloon.java8x;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created by wiloon on 12/3/16;
 */
public class TimeZonex {
    public static void main(String[] args) {
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        // zoneId = ZoneId.of("Australia/Sydney");
        String str = "2016-11-26 03:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateAndTime = LocalDateTime.parse(str, formatter);
        localDateAndTime = LocalDateTime.now();
        ZonedDateTime dateAndTimeInShanghai = ZonedDateTime.of(localDateAndTime, zoneId);

        System.out.println("Current date and time in a particular timezone : " + dateAndTimeInShanghai);

        ZonedDateTime utcDate = dateAndTimeInShanghai.withZoneSameInstant(ZoneOffset.UTC);

        System.out.println("Current date and time in UTC : " + utcDate);


        LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(1481732517, 0, ZoneOffset.of("+08:00"));
        System.out.println(localDateTime);
    }
}
